<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>state</title>
</head>
<body>
    <div id="test1"></div>
    <div id="test2"></div>
    <div id="test3"></div>
    <script src="../../17之前版本/react.development.js"></script>
    <script src="../../17之前版本/react-dom.development.js"></script>
    <script src="../../17之前版本/prop-types.js"></script>
    <script src="../../17之前版本/babel.min.js"></script>

    <script type="text/babel">
        function Demo(props){
            const { name,age,sex,speak } = props
            return (
                <ul>
                    <li onClick={speak}>姓名：{name}</li>
                    <li>性别：{sex}</li>
                    <li>年龄：{age}</li>
                </ul>
            )
        }
        Demo.propTypes ={
            name:PropTypes.string.isRequired,
            sex:PropTypes.string,
            age:PropTypes.number,
            speak:PropTypes.func
        }
        Demo.defaultProps = {
            sex:'未知',
            age:18
        }
        const person = {
            name:"老刘",
            age:18,
            sex:'男'
        }
        ReactDOM.render(<Demo name="tom" age={19} sex="男"/>,document.getElementById('test1'))
        ReactDOM.render(<Demo name="jack" age={18} sex="女" speak={speak}/>,document.getElementById('test2'))
        ReactDOM.render(<Demo {...person}/>,document.getElementById('test3'))

        function speak(){
            console.log('刚刚有人说话了，是你吗？');
            
        }
    </script>
</body>
</html>